import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';

/// 任务entity
class TaskEntity {
  late String? id;
  late String content;
  /// 截止时间。
  String? cutOffDate = DateTime.now().toIso8601String();
  /// 提醒时间。
  String? remindDate = DateTime.now().toIso8601String();
  /// 是否完成
  bool isSuccess = false;

  TaskEntity({ this.id, required this.content, this.cutOffDate, this.remindDate});

  TaskEntity.fromJson(Map<String, dynamic> json)
      : id = json['id'],
        content = json['content'],
        cutOffDate = json['cutOffDate'],
        remindDate = json['remindDate'],
        isSuccess = json['isSuccess']
  ;

  Map<String, dynamic> toJson() => {
    'id': id,
    'content': content,
    'cutOffDate': cutOffDate,
    'remindDate': remindDate,
    'isSuccess': isSuccess,
  };

  static List<String> entityListToJson(List<TaskEntity> taskList) {
    List<String> result = [];
    for (TaskEntity task in taskList) {
      result.add(jsonEncode(task));
    }
    return result;
  }

  static TaskEntity jsonToEntity(String jsonEntity) {
    return TaskEntity.fromJson(jsonDecode(jsonEntity));
  }

  static List<TaskEntity> jsonToList(List<String> jsonList) {
    List<TaskEntity> result = [];
    for (int i = 0; i < jsonList.length; ++i) {
      result.add(jsonToEntity(jsonList[i]));
    }

    return result;
  }
}

/// 添加任务选项模型
class AddTaskOptions {
  IconData icon;
  String? text;
  TaskType? taskType;

  AddTaskOptions({required this.icon,  this.text, this.taskType});
}

/// 任务类型
enum TaskType {
  today("我的一天"), //今日
  task("任务"),

  cutOffDate("设置截止日期"),
  remindDate("提醒日期"),

  ; //任务

  const TaskType(this.desc);
  final String desc;

}